package com.hundsun.hsOffer.controller;

import com.hundsun.hsOffer.intercept.EnhanceInterceptor;
import com.hundsun.hsOffer.model.SysUsers;
import com.hundsun.hsOffer.test.UserService;
import com.jfinal.core.Controller;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;

/**
 * Create By IDEA
 * User:giegie
 * Date:2016/8/18
 * Description:主页面跳转控制器
 */
public class IndexController extends Controller {
    /**
     * 报价系统index页面
     */
    public void index() {
        System.out.println(getPara("username"));
        renderFreeMarker("/index.ftl");
    }

    /**
     * 登录页面
     */
    public void login() {
        renderFreeMarker("login.ftl");
    }

    public void userLogin() {
        SysUsers userDto = getModel(SysUsers.class,"",true);
        Subject currentUser = SecurityUtils.getSubject();
        // 校验用户信息
        UsernamePasswordToken token = new UsernamePasswordToken(
                userDto.getUsername(), userDto.getPassword());
        try {
            currentUser.login(token);
            redirect("/index");
        } catch (Exception e) {
            setAttr("error", "账号或者密码错误");
            render("login.ftl");
        }
    }

    public void unauthorized(){
        render("unauthorized.ftl");
    }


}
